<?php

namespace app\api\validate;

use app\common\business\Category;
use app\common\business\WorkType;
use app\common\lib\Num;
use app\common\lib\Str;
use think\Validate;

class FeedBack extends Validate
{
    protected $rule = [
        'category_id' => 'require|number|checkCategory',
        'attachment' => 'require',
        'content' => 'require',
    ];

    protected $message = [
        'category_id.require' => '反馈分类必须',
        'category_id.number' => '反馈分类错误',
        'attachment' => '图片必须',
        'content' => '反馈内容必须',
    ];

    protected function checkCategory($value, $rule, $data = [])
    {
        return $this->checkCommonCategory('投诉建议反馈分类',$value);
    }
    protected function checkCommonCategory($name,$value)
    {
        try {
            (new Category())->checkValidValueByName($name,$value);
        } catch (\Exception $e) {
            return $e->getMessage();
        }
        return true;
    }

    protected $scene = [
        'save'=> ['category_id','content'],
    ];
}